import defaultSettings from '@/settings';
import { useDynamicTitle } from '@/utils/dynamicTitle';

const {
  sideTheme,
  showSettings,
  topNav,
  tagsView,
  fixedHeader,
  sidebarLogo,
  dynamicTitle,
  ItExpired,
} = defaultSettings;

const storageSetting = JSON.parse(localStorage.getItem('layout-setting')) || '';

const useSettingsStore = defineStore('settings', {
  state: () => ({
    title: '',
    ItExpired: true,
    watermark: '',
    theme: storageSetting.theme || '#409EFF',
    sideTheme: storageSetting.sideTheme || sideTheme,
    showSettings: showSettings,
    topNav:
      storageSetting.topNav === undefined ? topNav : storageSetting.topNav,
    // 暂时不要
    // tagsView:
    //   storageSetting.tagsView === undefined
    //     ? tagsView
    //     : storageSetting.tagsView,
    tagsView: false,
    fixedHeader: true,
    sidebarLogo:
      storageSetting.sidebarLogo === undefined
        ? sidebarLogo
        : storageSetting.sidebarLogo,
    dynamicTitle:
      storageSetting.dynamicTitle === undefined
        ? dynamicTitle
        : storageSetting.dynamicTitle,
    h5addr: '',
    menuIcon: {
      bigImg: '',
      logo: '',
      smallImg: '',
    },
    beOverdue: {
      mobile: '',
      qrUrl: '',
      pv: '',
      registerNum: '',
    },
    entranceUrl: {
      xcx: '',
      app: '',
      h5: '',
      pc: '',
      logoUrl: '',
    },
    applicationInfo: {
      expiredate_time: '',
      appId: '',
    },
  }),
  actions: {
    setPlatformInfo(info) {
      this.platformInfo = info.data; // 更新 platformInfo 的值
    },
    // 修改布局设置
    changeSetting(data) {
      const { key, value } = data;
      if (this.hasOwnProperty(key)) {
        this[key] = value;
      }
    },
    // 设置网页标题
    setTitle(title) {
      this.title = title;
      useDynamicTitle();
    },
    //设置图标
    setMenuIcon(data) {
      this.menuIcon = data;
    },
    //获取过期页面数据
    setBeOverdue(data) {
      this.beOverdue = data;
    },
    // 设置入口链接
    setEntranceUrl(data) {
      this.entranceUrl = data;
    },
    // 已购买应用
    setApplicationInfo(data) {
      this.applicationInfo = data;
    },
    //是否过期
    HasItExpired(data) {
      this.ItExpired = data;
    },
    setwWtermark(data) {
      this.watermark = data;
    },
    setH5addr(data) {
      this.h5addr = data;
    },
  },
});

export default useSettingsStore;
